<?php
define('BOOK',true);
require "include/common.php";
@$act=$_GET['act'];
if (empty($act)){
    $act="log";
}
session_start();
        switch ($act){
            case "log":
                include tpl('login');
                break;
            case "login":
                $loginName=$_POST['loginName'];
                $password=$_POST['password'];
                if (empty($loginName)||empty($password)){
                    show("请检查用户名或者密码","login.php?act=log");
                    exit();
                }

                $sql = "SELECT * FROM `admin` WHERE username='".$loginName."' AND password='".md5($password)."' ";
                $result=$conn->query($sql);
                $row = $result->fetch_array();
                if($row){

                    $_SESSION['userid']  = $row['id'];
                    $_SESSION['username'] = $row['username'];
                    show('登陆成功', 'houtai.php?act=main');
                }else{
                    show('登陆失败,检查用户名密码', 'login.php?act=log');
                }
                break;
            case "logout":
                session_destroy();
                show("账号退出成功","login.php?act=log");
        break;

}